package com.abocode.aichat.app.configuration;

import com.abocode.aichat.app.auth.AuthInterceptor;
import com.abocode.aichat.app.auth.AuthUnloginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by guanxf on 2015/12/16.
 */
@Configuration
@EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
    @Autowired
    private AuthUnloginInterceptor authUnloginInterceptor;
    @Autowired
    private AuthInterceptor authInterceptor;

    @Value("${auth.unlogin.urls}")
    private String urls;
    @Value("${auth.debug.switch}")
    private boolean debugSwitch;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        if (!debugSwitch) {
            String[] pathPatterns = urls.split(",");
            registry.addInterceptor(authUnloginInterceptor).addPathPatterns("/**");
            registry.addInterceptor(authInterceptor).addPathPatterns("/**").excludePathPatterns(pathPatterns);
        }
    }


}
